package vn.game;

import java.util.ArrayList;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CrosswordHintArrayAdapter extends ArrayAdapter<String> {

	private final Activity context;
	private final ArrayList<String> hints;
	
	private int selectedPos = -1;
	
	public CrosswordHintArrayAdapter(Activity context, ArrayList<String> hints) {
		super(context, R.layout.hint_row, hints);
		this.context = context;
		this.hints = hints;
	}

	static class ViewHolder{
		public TextView textView;
	}
	
	public void setSelectedPosition(int pos){
		selectedPos = pos;
		// inform the view of this change
//		notifyDataSetChanged();
	}

	public int getSelectedPosition(){
		return selectedPos;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		
		View rowView = convertView;
		
		if(rowView == null){
			LayoutInflater inflater = context.getLayoutInflater();
			rowView = inflater.inflate(R.layout.hint_row, null, true);
			holder = new ViewHolder();
			holder.textView = (TextView) rowView.findViewById(R.id.txt_item_list_hint);
			rowView.setTag(holder);
		}
		else{
			holder = (ViewHolder) rowView.getTag();
		}
		
//		if(selectedPos == position){
//			holder.textView.setBackgroundColor(Color.YELLOW);
//        }else{
//        	holder.textView.setBackgroundColor(Color.TRANSPARENT);
//        }
		
		holder.textView.setText((String)hints.get(position));
		
		return rowView;
	}
}
